package com.abcdefg.java_chatroom.api;

import com.abcdefg.java_chatroom.mapper.MessageMapper;
import com.abcdefg.java_chatroom.model.Message;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Collections;
import java.util.List;

@RequestMapping("/MessageApi")
@RestController
public class MessageApi {
    @Autowired
    private MessageMapper messageMapper;

    @GetMapping("/getMessage")
    public Object getMessage(int sessionId){
        List<Message> message=messageMapper.getMessageBySessionId(sessionId);
        Collections.reverse(message);
        return message;
    }
}
